<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
      layout:decorator="themes/default/layout/public">

<head>
    <link th:href="@{/static/js/summernote/summernote.css}" rel="stylesheet"/>
</head>
<div  layout:fragment="content">
    <div class="row mt-10">
        <ol class="breadcrumb">
            <li><a href="/questions">问答</a></li>
            <li><a th:href="|/question/${answer.question.id}|" th:text="${answer.question.title}"></a></li>
            <li class="active">编辑回答</li>
        </ol>
        <form th:object="${answer}" id="answer_form" method="POST" role="form" th:action="${#request.getRequestURI()}">
            <input type="hidden" th:value="${answer.id}" name="id"/>
            <div class="form-group" th:classappend="${#fields.hasErrors('content')}?'has-error'">
                <div id="answer_editor" th:utext="${answer.content}"></div>
                <p class="help-block" th:if="${#fields.hasErrors('content')}" th:text="${#fields.errors('content')}[0]"> </p>
            </div>
            <div class="row mt-20">
                <div class="col-xs-12 col-md-11">
                    <ul class="list-inline">

                        <li th:if="${GlobalSetting.irrigation.codeCreateAnswer}" class="pull-right">
                            <div class="form-group" th:classappend="${validateCodeError}?'has-error'">
                                <input type="text" class="form-control" name="captcha" required="" placeholder="验证码" />
                                <span th:if="${validateCodeError}" th:text="${validateCodeError}" class="help-block">{{ $errors->first('captcha') }}</span>
                                <div class="mt-10"><a href="javascript:void(0);" id="reloadCaptcha"><img src="/code/image?width=60&height=20"></a></div>
                            </div>
                        </li>

                    </ul>
                </div>
                <div class="col-xs-12 col-md-1">
                    <input type="hidden" id="answer_editor_content"  name="content" th:value="${answer.content}"  />
                    <button type="submit" class="btn btn-primary pull-right editor-submit" >保存修改</button>
                </div>
            </div>
        </form>
    </div>
    <script type="text/javascript">
        var is_login =true;
    </script>
    <script th:src="@{/static/js/jquery.min.js}"></script>
    <script th:src="@{/static/css/bootstrap/js/bootstrap.min.js}"></script>
    <script th:src="@{/js/global.js?v=20170412}"></script>
    <script th:src="@{/static/js/summernote/summernote.min.js}"></script>
    <script th:src="@{/static/js/summernote/lang/summernote-zh-CN.min.js}"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            /*回答编辑器初始化*/
            $('#answer_editor').summernote({
                lang: 'zh-CN',
                height: 240,
                placeholder:'撰写答案',
                toolbar:  [ ['common', ['style','bold','ol','link','picture','clear','fullscreen']] ],
                callbacks: {
                    onChange:function (contents, $editable) {
                        var code = $(this).summernote("code");
                        $("#answer_editor_content").val(code);
                    },
                    onImageUpload: function(files) {
                        upload_editor_image(files[0],'answer_editor');
                    }
                }
            });
        });

    </script>
</div>